<template>
	<view :class="themeName">
		<view class="flex heads">
			<view @click="choose('day')" class="h1" :class="{'h2':type=='day'}">当日</view>
			<view @click="choose('week')" class="h1" :class="{'h2':type=='week'}">一周</view>
			<view @click="choose('month')" class="h1" :class="{'h2':type=='month'}"> <text
					class="m-r-12">{{time}}</text>
				<u-icon name="arrow-down"></u-icon>
			</view>
		</view>
		<u-picker v-model="show" :confirm-color="themeColor" cancel-color="#999" mode="time2" @confirm="regionChange">
		</u-picker>
		<mescroll-uni 
			ref="mescrollRef" 
			bgColor="white"
			top="0"
			:up="{
				auto: true,
				noMoreSize: 4,
				empty: {
					icon: '/static/images/empty/order.png',
					tip: '暂无订单~',
					fixed: true
				}
			}"
			:down="{ auto: false }"
			@init="mescrollInit"
			@down="downCallback"
			@up="upCallback">
			<view class="store-container">
				<view v-for="(item, index) in lists" :key="index" class="store-item m-b-20">
					<view class="back md m-b-20">订单编号：{{item.sn}}</view>
					<view class="flex msg">
						<image class="img" :src="item.image" mode=""></image>
						<view class="s-boxs">
							<view class="sm back line-2">{{item.title}}</view>
							<view class="sm lighter m-t-10 m-b-10">服务时长：{{item.total_num}}分钟</view>
							<view class="sm" style="color: #0980CC;">￥{{item.total_amount}}</view>
						</view>
					</view>
					<view class="flex row-between m-t-20">
						<view class="muted nr">
							<view>服务门店：{{item.shopname}}</view>
							<view>服务机器：{{item.jqrname}}</view>
							<view>{{item.time}}</view>
						</view>
						<view class="md" style="color: #0980CC;" v-if="shenfen==1">+{{item.jxs_price}}</view>
						<view class="md" style="color: #0980CC;" v-else-if="shenfen==2">+{{item.shop_price}}</view>
					</view>
				</view>
			</view>
			<loading-view v-if="loading"></loading-view>
		</mescroll-uni>
		
	</view>
</template>

<script>
	import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
	import { fyOrderList } from '@/api/others.js';
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				shenfen:1,//1经销商   2门店
				type: 'day', //day 当日   week 一周  month 年月
				show: false,
				time: '',
				loading: true,
				lists: []
			};
		},
		onLoad(options) {
			this.shenfen = options.shenfen;
			this.gettime();
		},
		methods: {
			gettime() {
				let today = new Date();
				let year = today.getFullYear();
				let month = today.getMonth() + 1;
				if (month < 10) {
					month = '0' + String(month)
				}
				// console.log(year,month);
				this.time = year + '-' + Number(month);
			},
			choose(str) {
				if (str == 'month') {
					this.show = true;
				} else {
					this.type = str;
					this.mescroll.resetUpScroll();
				}
			},
			regionChange(e) {
				console.log(e.year)
				console.log(e.month)
				this.type = 'month';
				this.time = e.year + '-' + e.month;
				
				this.mescroll.resetUpScroll();
			},
			// 下拉刷新
			downCallback() {
				this.upCallback({
				    num: 1,
				    size: 10
				});
			},
			// 上拉加载
			upCallback({ num, size }) {
				fyOrderList({
					type: this.type,
					time: this.time,
					page_no: num,
					page_size: size
				})
					.then((res) => {
						if (num == 1) this.lists = []; //如果是第一页需手动置空列表
						this.lists = this.lists.concat(res.lists); //追加新数据
						this.mescroll.endSuccess(res.lists.length, res.count);
						setTimeout(() => {
							this.loading = false;
						}, 500);
					})
					.catch((err) => {
						this.mescroll.endErr()
					});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.heads {
		padding: 20rpx;
		position: relative;
		z-index: 2;
		background: #F6F6F6;
		.h1 {
			background-color: #fff;
			padding: 0rpx 30rpx;
			border-radius: 15rpx;
			margin-right: 30rpx;
			border: 1px solid #eee;
			height: 67rpx;
			line-height: 67rpx;
		}

		.h2 {
			border: 1px solid #0980CC;
		}
	}
	.store-container {
		position: relative;
		z-index: 1;
		background-color: white;
		margin-top: 120rpx;
		.store-item {
			padding: 20rpx 30rpx;
			border-radius: 10rpx;
	
			.img {
				width: 180rpx;
				height: 180rpx;
				margin-right: 20rpx;
			}
			.msg{
				padding: 20rpx 0;
				border-top: 1px solid #eee;
				border-bottom: 1px solid #eee;
			}
			.s-boxs{
				flex: 1;
				line-height: 36rpx;
				
				.line-2{
					height: 75rpx;
				}
			}
			.s-go{
				white-space: nowrap;
				color: #0980CC;
				font-size: 28rpx;
			}
		}
	}
</style>